<?php

namespace Modules\Order\Entities;

use Illuminate\Database\Eloquent\Builder;

use ThrowException;

class AgentOrder extends BaseOrder
{
    // 代付订单

    protected $guarded = [];
    protected $table = 'orders';
    static public $orderType = 'agent';

    static public $resourceName = '代付订单';

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('agentOrder', function(Builder $builder) {
            $builder->type('agent');
        });
    }

    // 所属代付记录
    public function agent_pay_record()
    {
        return $this->hasOne('\Modules\Order\Entities\AgentPayRecord', 'agent_order_id');
    }

    public function generateNumber()
    {
        $number = 'AG' . date('ymdHis') . $this->user_id . '0' . rand(10000, 99999);
        return $number;
    }

    // public function generateTitle()
    // {
    //     return '《' . $this->single_sku->title . '》预约';
    // }

    public function paidListenerSync()
    {
        // $this->ticket->pay_status = 1;
        // $this->ticket->save();

        // $this->autoFreight();
        \Log::error('agent order pay: ' . $this->id);
        $this->agent_pay_record->finishPay();
    }

}
